package com.weiiew.backend.executor;

import com.weiiew.backend.entity.TerminationPolicy;
import com.weiiew.backend.entity.config.ScriptConfig;
import com.weiiew.backend.entity.enums.LogState;
import org.springframework.stereotype.Component;

/**
 * @author 魏锴
 * @since 2025/5/4
 */
@Component
public class ScriptExecutor extends baseExecutor<ScriptConfig> {

    @Override
    protected void initResource(ScriptConfig config) {
        TerminationPolicy policy = new TerminationPolicy();
        policy.setType(TerminationPolicy.StopType.EXECUTION);
        policy.setMaxExecutions(1);
        executor.setOperations(config.getSequence());
        executor.setTerminationPolicy(policy);
        executor.setLogger(messagingTemplate, config.getChannel());
        executor.setLogState(LogState.OPERATION);
    }

    @Override
    protected void clearResource() {
    }
}
